$(function(){
	//定义空全局变量	
	var cityCode;
    var nameCode;
    var sfCode;
    var jszCode;
    var carCode;
    var recordCode;
    
	//点击选择城市
	var city_name = getQueryStr("cityName");
	var city_id =getQueryStr("cityId");
	var telphone = localStorage.getItem("telphone");
	$.ajax({
            type: "post",
            url:"http://www.pdhz-dddc.cn/dingding-web/driverRecruitAction!getDriverRecruitInfo",
            dataType: "jsonp",
            async: false,
            jsonp: "callback",
            jsonpCallback: "success_jsonp",
            data:{
				telPhone:telphone
            },
            success: function(data){  
                if(data.code == 200){
                	var recId = data.responseBody.recId;
                	//session 读取 判断数据
                	var currentCityName = sessionStorage.getItem("cityName");
                	var cityName = data.responseBody.cityName;
                	console.log(cityName);
                	cityName = currentCityName == null ? cityName : currentCityName;
                	         	
                	var currentName = sessionStorage.getItem("name");
                	var name = data.responseBody.name;
                	name = currentName == null ? name : currentName;

                	var currentidCarName = sessionStorage.getItem("idCardNum");
                	var idCard = data.responseBody.idCard;
                	idCard = currentidCarName == null ? idCard : currentidCarName;

                	var currentdriLicDateName = sessionStorage.getItem("driLicDateNum");
                	var driLicDate = data.responseBody.driLicDate;
                	driLicDate = currentdriLicDateName == null ? driLicDate : currentdriLicDateName;

                	var currentcarTypeName = sessionStorage.getItem("carTypeNum");
                	var carType = data.responseBody.carType;
                	carType = currentcarTypeName == null ? carType : currentcarTypeName;

                	var currentlicDataNoName = sessionStorage.getItem("licDataNoNum");
                	var licDataNo = data.responseBody.licDataNo; 
                	licDataNo = currentlicDataNoName == null ? licDataNo : currentlicDataNoName;
                	//清除 
                	sessionStorage.clear();   
                	$(".city_btn").attr("placeholder","");            	            	          
//                	$(".city_btn").attr("value",cityName);
                	$(".city_btn").val(cityName); 
                	$(".sfNumber").attr("placeholder","");
                	$(".sfNumber").attr("value",idCard);
                	$(".driver_name").attr("placeholder","");
                	$(".driver_name").attr("value",name);
                	$(".jszDate").attr("placeholder","");
                	$(".jszDate").attr("value",driLicDate);
                	$(".carList").attr("placeholder","");
                	$(".carList").attr("value",carType);
                	$(".recordNum").attr("placeholder","");
                	$(".recordNum").attr("value",licDataNo);        	
                	$(".carBtn").css({"background":"#FF4C4B","color":"#FFFFFF"});
				    $(".carBtn").attr("disabled",false);   	    
				    $(".carBtn").on("click",function(){
						driLicDate = driLicDate+" 00:00:00";
						$(".carBtn").on("click",function(){
							$.ajax({
					            type: "post",
					            url:"http://www.pdhz-dddc.cn/dingding-web/driverRecruitAction!driverSignUp",
					            dataType: "jsonp",
					            async: false,
					            jsonp: "callback",
					            jsonpCallback: "success_jsonp",
					            data:{
					                cityId:city_id == "" ? data.responseBody.cityId : city_id,
									name: $(".driver_name").attr("value"),
									idCard: $(".sfNumber").attr("value"),
									driLicDate: $(".jszDate").attr("value"),
									carType: $(".carList").attr("value"),
									licDataNo: $(".recordNum").attr("value"),
									telPhone:telphone,
									recId: recId
					            },
					            success: function(data){
					                if(data.responseBody == "error"){
					                    swal({
								            title: "填写信息有误,报名失败!",
								            type: "warning",
								            confirmButtonColor: "#DD6B55",
								            confirmButtonText: "确定",
								        });
					                }else if(data.responseBody == "success"){     
					                    window.location.href = "prompt.html";
					                }
					            }
					        });
						});
						 
					});                 	
                }else if(data.code == 400){


            		var currentName = sessionStorage.getItem("name");
            		var currentNameNew = currentName == null ? "" : currentName;
            		$(".driver_name").attr("value",currentNameNew);

            		var currentIdCard = sessionStorage.getItem("idCardNum");
            		var currentIdCardNew = currentIdCard == null ? "" : currentIdCard;
            		$(".sfNumber").attr("value",currentIdCardNew);

            		var firstLicData = sessionStorage.getItem("driLicDateNum");
            		var firstLicDataNew = firstLicData == null ? "" : firstLicData;
            		$(".jszDate").val(firstLicDataNew);

            		var currentCarStyle = sessionStorage.getItem("carTypeNum");
            		var currentCarStyleNew = currentCarStyle == null ? "" : currentCarStyle;
            		$(".carList").attr("value",currentCarStyleNew);

            		var currentLicNo = sessionStorage.getItem("licDataNoNum");
            		var currentLicNoNew = currentLicNo == null ? "" : currentLicNo;
            		$(".recordNum").attr("value",currentLicNoNew);

                
                	//清除 
                	sessionStorage.clear();    

                	 //监听事件控制button 激活及其颜色控制
					$('input').bind('input propertychange', function() {
						cityCode = $(".city_btn").val();
						nameCode = $(".driver_name").val();
						sfCode = $(".sfNumber").val();
						jszCode = $(".jszDate").val();
						carCode = $(".carList").val();
						recordCode = $(".recordNum").val();
						if(cityCode!==""&&nameCode!==""&&sfCode!==""&&jszCode!==""&&carCode!==""&&recordCode!==""){
						    $(".carBtn").css({"background":"#FF4C4B","color":"#FFFFFF"});
						    $(".carBtn").attr("disabled",false);
						} 
					});    

                	//点击申请成为全职司机数据交互
					$(".carBtn").on("click",function(){
						 jszCode = jszCode +" 00:00:00";	
						 $.ajax({
					            type: "post",
					            url:"http://www.pdhz-dddc.cn/dingding-web/driverRecruitAction!driverSignUp",
					            dataType: "jsonp",
					            async: false,
					            jsonp: "callback",
					            jsonpCallback: "success_jsonp",
					            data:{
					                cityId:city_id,
									name:nameCode,
									idCard:sfCode,
									driLicDate:jszCode,
									carType:carCode,
									licDataNo:recordCode,
									telPhone:telphone
					            },
					            success: function(data){
					                if(data.responseBody == "error"){
					                    swal({
								            title: "填写信息有误,报名失败!",
								            type: "warning",
								            confirmButtonColor: "#DD6B55",
								            confirmButtonText: "确定",
								        });
					                }else if(data.responseBody == "success"){     
					                    window.location.href = "prompt.html";
					                }
					            }
					        });
					});
                   
            	}
            }
        });
	
	//判断city_name 清空placeholder
	if(city_name !== ""){
		$(".city_btn").attr("placeholder","");
	}else{
		$(".city_btn").attr("placeholder","请选择城市");
	}

	city_name = decodeURI(city_name);

	$(".city_btn").on("click",function(){
		window.location.href="city.html";
		//seeion 存储数据信息
		sessionStorage.setItem("name", $(".driver_name").attr("value"));
		sessionStorage.setItem("idCardNum", $(".sfNumber").attr("value"));
		sessionStorage.setItem("driLicDateNum",$(".jszDate").val());
		sessionStorage.setItem("carTypeNum",$(".carList").attr("value"));
		sessionStorage.setItem("licDataNoNum",$(".recordNum").attr("value"));
	})
	$(".city_btn").attr("value",city_name);

	//姓名焦点事件
	$(".driver_name").focus(function(){
		$(this).attr("placeholder","");
		$(this).attr("value","");
	});
	$(".driver_name").blur(function(){
		if($(".driver_name").val()==""){			
			swal({
                title: "请输入,您的姓名",
                type: "warning",
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
            });
			$(".driver_name").attr("placeholder","你的中文全名");
		}if($(".driver_name").val()!=="")
		{
			var name_z = $(this).val();
			$(".driver_name").attr("value",name_z);
		}
	})	

	//身份证信息验证	
	$(".sfNumber").focus(function(){
		$(this).attr("placeholder","");
		$(this).attr("value","");
	});
	$(".sfNumber").blur(function(){
		var identityNumber = $(".sfNumber").val();
		var zzNumber = /^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/;
		if(zzNumber.test(identityNumber)){
			$(".sfNumber").attr("value",identityNumber);
		}else{
			$(".sfNumber").val("");
			swal({
                title: "请输入正确格式身份证号码",
                type: "warning",
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
            });
			$(".sfNumber").attr("placeholder","请输入身份证号码");
		}
	})

	//初次领证日期 日历JS
	var currYear = (new Date()).getFullYear();	
	var opt={};
	opt.date = {preset : 'date'};
	opt.datetime = {preset : 'datetime'};
	opt.time = {preset : 'time'};
	opt.default = {
		theme: 'android-ics light', //皮肤样式
        display: 'modal', //显示方式 
        mode: 'scroller', //日期选择模式
		dateFormat: 'yyyy-mm-dd',
		lang: 'zh',
		showNow: true,
		nowText: "今天",
        startYear: currYear - 50, //开始年份
        endYear: currYear + 10 //结束年份
	};
  	$("#appDate").mobiscroll($.extend(opt['date'], opt['default']));
  	var optDateTime = $.extend(opt['datetime'], opt['default']);
  	var optTime = $.extend(opt['time'], opt['default']);
    $("#appDateTime").mobiscroll(optDateTime).datetime(optDateTime);
    $("#appTime").mobiscroll(optTime).time(optTime);
    
	//准驾车型
	$(".radio").on("click",function(){
		var nms1 = $(this).find(".label_list").text().trim();
		$(".carList").attr("value",nms1).attr("placeholder","");
		//取消模态框
		$('#myModal').modal('hide')
	})
	$(".carDiv").focus(function(){
		$(this).attr("placeholder","");
	});
	$(".carDiv").blur(function(){
		if($(".carDiv").val()==""){			
			$(".carDiv").attr("placeholder","请按驾照信息选择");
		}if($(".carDiv").val()!=="")
		{
			$(".carDiv").attr("placeholder","");
		}
	})	
	var car_z = $(".carDiv").val();
	$(".carDiv").attr("value",car_z); 
	//档案编码
	$(".recordNum").focus(function(){
		$(this).attr("placeholder","");
		$(this).val("");
	});



	$(".recordNum").blur(function(){
		var fileNumber = $(".recordNum").val();
		var fileNumberZ = /\b\d{12}\b/;
		if(fileNumberZ.test(fileNumber)){
			$(".recordNum").attr("value",fileNumber);
		}else{
			$(".recordNum").val("");
			swal({
                title: "请输入正确格式档案编号",
                type: "warning",
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
            });
			$(".recordNum").attr("placeholder","请输入身份证号码");
		}
	})	
});
//封装选择驾驶证类型弹框方法
function mtTest(){
	$('#myModal').modal('show');
}

